import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/global/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from '@dfeidao/atom-web/url/refresh';
import fire from '@dfeidao/atom-web/msg/fire';
export default async function a007(fd: IFeidaoAiBrowserComponent) {
	// todo
	const chk_list = fd.data.node.querySelectorAll('[data-id="list"]:checked');
	if (chk_list.length < 0) {
		alert("请选择一条数据进行操作");
	} else {
		const chklist = Array.from(chk_list) as HTMLInputElement[];
		const arr = chklist.map((n) => {
			return n.getAttribute('data-no');
		});
		console.log(arr);
	}

	const post_package = get('post_package');
	let ps = ''
	if (!post_package) {
		ps = get('post_package1')

	} else {
		ps = get('post_package')

	}
	//岗位编号
	const chklist = Array.from(chk_list) as HTMLInputElement[];
	const arr = chklist.map((n) => {
		return n.getAttribute('data-v');
	});

	//岗位名称
	const name = Array.from(chk_list) as HTMLInputElement[];
	const arr1 = name.map((n) => {
		return n.getAttribute('data-n');
	});
	const ad: number[] = []
	for (let i = 0; i < arr.length; i++) {
		const res = await nodejs<{ code: 0 | 1 }>('GuoKai/zj-000007/s002', {
			post_package: ps,
			post_name: arr1[i],
			page_no: 1,
			post_no: arr[i],
		});
		ad.push(res.code)
	}
	for (let index = 0; index < ad.length; index++) {
		if (ad[index] === 1) {
			alert("添加成功");
			fire('zj-000003', 'a012', post_package);
			fire('zj-000007', 'a002');
			fire('zj-000007', 'a003', 1);
			return;
		} else {
			alert("添加失败");
			return;
		}

	}

}
